#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "OLED.h"
#include "Serial.h"
#include "Key.h"

uint8_t KeyNum;

int main(void)
{
	/*模块初始化*/
	OLED_Init();		//OLED初始化
	Key_Init();			//按键初始化
	/*串口初始化*/
	Serial_Init();		//串口初始化
	
	/*显示静态字符串*/
	OLED_ShowString(1, 1, "TxPacket");
	OLED_ShowString(3, 1, "RxPacket");
	
	/*设置发送数据包数组的初始值，用于测试*/
	TxSerial_Data[0] = 0x01;
	TxSerial_Data[1] = 0x02;
	TxSerial_Data[2] = 0x03;
	TxSerial_Data[3] = 0x04;
	
	while (1)
	{
		KeyNum = Key_GetNum();
		if(KeyNum == 1)						//按键按下
		{
			TxSerial_Data[0] ++;			//测试数据自增
			TxSerial_Data[1] ++;
			TxSerial_Data[2] ++;
			TxSerial_Data[3] ++;
			
			Serial_TxData();
			
			OLED_ShowHexNum(2, 1, TxSerial_Data[0], 2);	//显示发送的数据包
			OLED_ShowHexNum(2, 4, TxSerial_Data[1], 2);
			OLED_ShowHexNum(2, 7, TxSerial_Data[2], 2);
			OLED_ShowHexNum(2, 10, TxSerial_Data[3], 2);
		}
		
		if(Serial_GetRxFlag() == 1)			//如果接收到数据包
		{
			OLED_ShowHexNum(4, 1, RxSerial_Data[0], 2);	//显示接收的数据包
			OLED_ShowHexNum(4, 4, RxSerial_Data[1], 2);
			OLED_ShowHexNum(4, 7, RxSerial_Data[2], 2);
			OLED_ShowHexNum(4, 10, RxSerial_Data[3], 2);
		}
	}
}

